package com.baibei.ebec.user.messagefollow;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.baibei.ebec.user.R;
import com.baibei.ebec.user.R2;
import com.baibei.model.FollowMsgInfo;
import com.baibei.module.AppRouter;
import com.baibei.order.bill.sticky_header.StickyDateAdapter;
import com.baibei.order.bill.viewtype.ViewType;
import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by tang on 2018/8/16.
 */

public class MessageFollowAdapter extends StickyDateAdapter<FollowMsgInfo> {
    private Context context;
    public MessageFollowAdapter(Context context){
        this.context = context;
    }
    @Override
    public RecyclerView.ViewHolder getItemViewHolder(final ViewGroup parent, int viewType) {
        if (viewType == ViewType.ITEM.ordinal()) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_follow_msg, parent, false);
            final ViewHolder viewHolder = new ViewHolder(view);
            viewHolder.tvTobuy.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    AppRouter.routeToMain(parent.getContext(),0);
                }
            });
            return viewHolder;
        }

        return null;
    }

    @Override
    public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof ViewHolder){
            ViewHolder viewHolder = (ViewHolder) holder;
            final FollowMsgInfo info = mRecordObjs.get(position);
            if ("1".equals(info.getType())){
                viewHolder.tvTobuy.setVisibility(View.VISIBLE);
            }
            viewHolder.tvTime.setText(info.getTime());
            viewHolder.content.setText(info.getMessage());
            viewHolder.content.setMovementMethod(ScrollingMovementMethod.getInstance());
            Glide.with(context).load(info.getUserPic()).into(viewHolder.iv);
            viewHolder.iv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    AppRouter.routeToFollowerDetail(context,info.getFollowerId());
                }
            });
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R2.id.tv_time)
        TextView tvTime;
        @BindView(R2.id.iv)
        ImageView iv;
        @BindView(R2.id.content)
        TextView content;
        @BindView(R2.id.tv_tobuy)
        TextView tvTobuy;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
